<template>
  <Container class="public-edit">
    <!-- 基础设置 -->
    <div class="container-header title title-center" slot="header">
      查看签约门店
      <Button
        size="large"
        class="fl btn-back"
        icon="ios-arrow-back"
        @click="jumpPrevPage"
      >返回</Button>
    </div>
    <Tabs v-model="tab" type="card" size="small">
      <TabPane label="基础信息" name="tab0" />
      <TabPane label="签约信息" name="tab1" />
      <TabPane label="门店照片" name="tab2" />
      <TabPane label="门店身份证" name="tab3" />
      <TabPane label="合同签约记录" name="tab4" />
      <TabPane label="变更记录" name="tab5" />
      <TabPane label="扫码地址" name="tab6" />
    </Tabs>
    <div class="tab-content">
      <StoreBaseInfoItem :form="form" v-show="tab=='tab0'" />
      <StoreInfoItem :isShowSignInfo='false' :form="form" v-show="tab=='tab1'"  />
      <StorePictures :form="form" v-show="tab=='tab2'"  />
      <IDcardPictures ref="id-card" :form="form" :isFromPublic="true" @checkNo="checkNo" v-show="tab=='tab3'"  />
      <SignRecordItem :form="form"  v-show="tab=='tab4'" />
      <ChangeInfo :form="form" v-show="tab=='tab5'"  />
      <AddressMap :isEdit="false" :form="form" v-show="tab=='tab6'"  />
    </div>
    <div class="container-footer bg-white" slot="footer" v-show="tab=='tab3'">
      <Button type="primary" size="large" class="ml" @click="onSave" :disabled="disabled">保存</Button>
    </div>
  </Container>
</template>
<script>
  import StoreBaseInfoItem from "../storesign/edit/StoreBaseInfoItem";
  import StoreInfoItem from "../storesign/edit/StoreInfoItem";
  import StorePictures from '../storesign/edit/StorePicturesItem'
  import ChangeInfo from '../storesign/edit/ChangeInfoItem'
  import AddressMap from '../storesign/edit/AddressMapItem'
  import IDcardPictures from '../storesign/edit/IDcardPicturesItem'
  import SignRecordItem from '../storesign/edit/SignRecordItem'

  export default {
    name: "",
    components: {
      StoreBaseInfoItem,
      StoreInfoItem,
      StorePictures,
      ChangeInfo,
      AddressMap,
      IDcardPictures,
      SignRecordItem
    },
    data() {
      return {
        tab: 'tab1',
        form: {
          cardz: [],
          cardf: [],
          yyzz: [],
          storeContractAgreementDTOList: [],
          storeContractChangeLogDTOList: [],
          empowerBrandDTOList: [],
          storeContractDTO: {
            distributorId: '',
            distributorName: '',
            storeContractBrandDTOList: [],
            storeContractAgreementDTO: {}
          },
          storeDTO: {}
        },
        isBlurExit: false,
        disabled: false
      }
    },
    mounted() {
      this.id = this.$route.query.id
      this.getData()
    },
    methods: {
      getData() {
        if (!this.id) return
        this.$ajaxGet(`/contract_store/detail/${this.id}`).then(res => {
          this.form = Object.assign(this.form, res)
          if (!this.form.storeContractDTO.storeContractExtDTO) {
            this.form.storeContractDTO.storeContractExtDTO = {}
          }
          if (!this.form.storeContractDTO.storeContractAgreementDTO) {
            this.form.storeContractDTO.storeContractAgreementDTO = {}
          }
        })
      },
      jumpPrevPage() {
        this.$router.back()
      },
      async onSave() {
        if (this.disabled) return
        this.disabled = true
        await this.checkNo().then(() => {
          let form = this.$refs['id-card'].form
          if (this.isBlurExit) {
            this.disabled = false
            return
          }
          let params = {
            businessLicenseNo: form.storeContractDTO.businessLicenseNo,
            contractId: this.id,
            ownerIdcardNo: form.storeContractDTO.ownerIdcardNo,
            ownerName: form.storeContractDTO.ownerName
          }
          this.$jsonPost('/store_public_resource/update', params).then(() => {
            this.disabled = false
            this.$Notice.success({
              title: '修改成功'
            })
          }).catch(() => {
            this.disabled = false
          })
        })
      },
      checkNo(v) {
        return new Promise((resolve, reject) => {
          this.isBlurExit = v
          resolve()
        })
      }
    }
  };
</script>
